﻿using Core.ApplicationServices;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Infrastructure.ApplicationServices
{
    public class FileWriter : IRepository
    {
        private readonly IConfigurable appConfig;

        public FileWriter(IConfigurable config)
        {
            this.appConfig = config;
        }

        public void AppendItems(string wokingfolder, string category, IList<string> items)
        {
            if (string.IsNullOrEmpty(wokingfolder) || items == null || items.Count == 0) return;


            if (!Directory.Exists(wokingfolder))
            {
                Directory.CreateDirectory(wokingfolder);
            }

            string path = wokingfolder + Path.DirectorySeparatorChar + string.Concat(category, ".txt");
            using (StreamWriter write = File.AppendText(path))
            {
                foreach (var text in items) write.Write(text + Environment.NewLine);
            }
        }
    }
}
